package com.briup.jz.service.impl;

import java.util.Date;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.AccountSystem;
import com.briup.jz.bean.AccountSystemExample;
import com.briup.jz.dao.AccountSystemMapper;
import com.briup.jz.service.IAccountSystemService;
import com.briup.jz.utils.CustomerException;
@Service
public class AccountSystemServiceImpl implements IAccountSystemService{
	@Autowired
	private AccountSystemMapper accountSystemMapper;
	
	@Override
    public List<AccountSystem> query(Double transfer_money, String type, String status ) {
    	AccountSystemExample example = new AccountSystemExample();
    	AccountSystemExample.Criteria criteria = example.createCriteria();
    	
    	if(status !=null) {
			criteria.andStatusEqualTo(status);			
		}
		if(type !=null) {
			criteria.andTypeLike("%"+type+"%");
			
		}
		if(transfer_money !=null) {
			criteria.andTransferMoneyEqualTo(transfer_money);
		}
    	
    	return accountSystemMapper.selectByExample(example);
    }


	@Override
	public void saveOrUpdate(AccountSystem accountSystem) throws Exception {
		// TODO Auto-generated method stub
		if(accountSystem.getId()!=null) {
   		 	// 初始化属性
        	accountSystem.setTransferTime(new Date().getTime());
        	accountSystem.setStatus("未审核");
            // 插入到数据库
			accountSystemMapper.updateByPrimaryKey(accountSystem);
		} else {
			accountSystemMapper.insert(accountSystem);
		}
	}


	@Override
	public void deleteById(long id) throws CustomerException {
		AccountSystem accountSystem = accountSystemMapper.selectByPrimaryKey(id);
        if (accountSystem == null) {
            throw new CustomerException("要删除的系统账单不存在");
        } else {
            accountSystemMapper.deleteByPrimaryKey(id);
        }		
	}
}
